package com.cg.design.graphicdesignpattern.prototype;

import com.cg.design.graphicdesignpattern.prototype.framework.Product;

/**
 * Product接口的具体子类（用某字符环绕字符串）
 *
 * @program: LeetCode->MessageBox
 * @description: Product接口的具体子类（用某字符环绕字符串），负责实现复制现有实例并生成新实例的方法
 * @author: cg
 * @create: 2022-03-20 16:14
 **/
public class MessageBox implements Product {

    private char decodeChar;

    public MessageBox(char decodeChar) {
        this.decodeChar = decodeChar;
    }

    @Override
    public void use(String s) {
        int length = s.getBytes().length;
        for (int i = 0; i < length + 4; i++) {
            System.out.print(decodeChar);
        }
        System.out.println("");
        System.out.println(decodeChar + " " + s + " " + decodeChar);
        for (int i = 0; i < length + 4; i++) {
            System.out.print(decodeChar);
        }
        System.out.println("");
    }

    @Override
    public Product createClone() {
        Product product = null;
        try {
            product = (Product) clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return product;
    }
}
